<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;

class FileController extends Controller
{
    public function index(Request $request) {
        $folder = $request->get('folder');
        $directories = Storage::directories("${folder}");
        $files = Storage::files("${folder}");
        return view('file.index',compact('files','directories'));
    }

    public function store(Request $request) {

        $folder = $request->get('folder');
        $img = $request->file('image');
        Storage::putFile($folder,$img);
        return redirect()->refresh();
    }

    public function download(Request $request) {
        $path = $request->get('path');
        return response()->download("storage/".$path);
    }

}
